﻿using UnityEngine;

namespace CinemaDirector
{
    /// <summary>
    /// The ActorTrackGroup maintains an Actor and a set of tracks that affect 
    /// that actor over the course of the Cutscene.
    /// </summary>
    [TrackGroupAttribute("ParticleSystem Track Group", TimelineTrackGenre.ActorTrack)]
    public class ParticleSystemTrackGroup : ActorTrackGroup
    {
        private ParticleSystem[] particles = null;

        public override void Initialize()
        {
            base.Initialize();
            particles = Actor.GetComponentsInChildren<ParticleSystem>(true);
        }

        public override void UpdateTrackGroup(float time, float deltaTime)
        {
            foreach (var ps in particles)
            {
                if (ps.gameObject.activeInHierarchy)
                {
                    ps.Simulate(deltaTime, true, false);
                }
            }
            base.UpdateTrackGroup(time, deltaTime);
        }
    }
}